import 'package:flutter/material.dart';
import 'package:get/get.dart';

import './module/menu.dart';
import '/router/router.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'package:owner_flutter/utils/localStorage.dart';
import 'home/home_view.dart';
import 'package:owner_flutter/page/commmunity/communityPage.dart';
import 'package:owner_flutter/page/entranceGuard/entranceGuardPage.dart';
import 'package:owner_flutter/page/housekeeper/HouseKeeperPage.dart';
import 'package:owner_flutter/page/myCenter/myCenterPage.dart';
import 'package:owner_flutter/page/demo/formDemo.dart';

class IndexPage extends StatefulWidget {
  const IndexPage({Key? key}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  int _currentIndex = 0;
  List pageList = [
    HomePage(),
    CommunityPage(),
    EntranceGuardPage(),
    // HouseKeeperPage(),
    FormDemoPage(),
    MyCenterPage()
  ];
  @override
  void initState() {
    _auth();
    super.initState();
  }

  _auth() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String accessToken = prefs.getString(LocalStorage.TOKEN) ?? '';
    if (accessToken == '') {
      Get.toNamed(RouteConfig.login);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: pageList[_currentIndex],
        bottomNavigationBar: ConvexAppBar(
          backgroundColor: Colors.deepPurple,
          style: TabStyle.react,
          items: [
            TabItem(icon: Icons.home, title: '首页'),
            TabItem(icon: Icons.card_travel, title: '邻里圈'),
            TabItem(icon: Icons.vpn_key, title: '门禁'),
            TabItem(icon: Icons.supervised_user_circle, title: '管家'),
            TabItem(icon: Icons.account_circle, title: '我的'),
          ],
          initialActiveIndex: 0, //optional, default as 0
          onTap: (int i) => setState(() => {_currentIndex = i}),
        ));
  }
}
